# 导包
import time

from selenium import webdriver
from selenium.webdriver.common.by import By


# 创建测试类
class TestLogin:
    # 类前置方法
    def setup_class(self):
        # 创建浏览器驱动对象
        self.driver = webdriver.Chrome()
        # 最大化浏览器
        self.driver.maximize_window()
        # 隐式等待
        self.driver.implicitly_wait(10)

    def setup_method(self):
        # 打开登录
        self.driver.get("https://hmshop-test.itheima.net/index.php/Home/user/login.html")

    def teardown_method(self):
        # 等待
        time.sleep(3)

    def teardown_class(self):
        # 关闭浏览器
        self.driver.quit()

    # 用户名为空
    def test01_login_username_empty(self):
        self.driver.find_element(By.ID, "username").send_keys("")
        self.driver.find_element(By.ID, "password").send_keys("123456")
        self.driver.find_element(By.ID, "verify_code").send_keys("8888")
        self.driver.find_element(By.LINK_TEXT, "登    录").click()
        pass

    # 密码为空
    def test02_login_password_empty(self):
        self.driver.find_element(By.ID, "username").send_keys("13488888888")
        self.driver.find_element(By.ID, "password").send_keys("")
        self.driver.find_element(By.ID, "verify_code").send_keys("8888")
        self.driver.find_element(By.LINK_TEXT, "登    录").click()
        pass

    # 登录成功
    def test03_login_success(self):
        self.driver.find_element(By.ID, "username").send_keys("13488888888")
        self.driver.find_element(By.ID, "password").send_keys("123456")
        self.driver.find_element(By.ID, "verify_code").send_keys("8888")
        self.driver.find_element(By.LINK_TEXT, "登    录").click()
        pass